import { createRouter, createWebHistory } from 'vue-router'

const routes = [
  {
    path: '/',
    component: () => import('../views/Layout.vue'),
    children: [
      {
        path: '',
        name: 'device',
        component: () => import('../views/device/DeviceList.vue')
      },
      {
        path: 'scene',
        name: 'scene',
        component: () => import('../views/scene/SceneList.vue')
      },
      {
        path: 'timer',
        name: 'timer',
        component: () => import('../views/timer/TimerList.vue')
      }
    ]
  }
]

console.log('配置的路由:', routes)

const router = createRouter({
  history: createWebHistory(),
  routes
})

router.beforeEach((to, from, next) => {
  console.log('路由导航:', {
    from: from.path,
    to: to.path,
    matched: to.matched.map(r => r.path)
  })
  next()
})

export default router 